package com.farmer.controller;

import com.farmer.pojo.Agritainment;
import com.farmer.pojo.Comment;
import com.farmer.pojo.Policy;
import com.farmer.service.AgritainmentService;
import com.farmer.service.PolicyService;
import com.farmer.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("agritainment")
@CrossOrigin
public class AgritainmentController {
    @Autowired
    private AgritainmentService agritainmentService;


//    @PostMapping(value="add",consumes = "multipart/form-data")
//    public Result add(@ModelAttribute Agritainment agritainment,@RequestBody MultipartFile file) {
//        Result result =agritainmentService.add(agritainment,file);
//        return result;
//    }
    @PostMapping("add")
    public Result add(Agritainment agritainment) {
    Result result = agritainmentService.add(agritainment);
    return result;
    }

    @DeleteMapping("delete")
    public Result delete(@RequestParam Integer id) {
        Result result = agritainmentService.delete(id);
        return result;
    }

    @DeleteMapping("delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        Result result = agritainmentService.deleteBatch(ids);
        return result;

    }
    @PutMapping("update")
    public Result update(@RequestBody Agritainment agritainment) {
        Result result = agritainmentService.update(agritainment);
        return result;
    }

    @GetMapping("getById")
    public Result getById(@RequestParam Integer id) {
        Result result = agritainmentService.getById(id);
        return result;
    }

    @GetMapping("getAll")
    public Result getAll() {
        Result result = agritainmentService.getAll();
        return result;
    }

    @GetMapping("getByTitleLike")
    public Result getByTitleLike(@RequestParam String title) {
        Result result = agritainmentService.getByTitleLike(title);
        return result;
    }
    @GetMapping("show")
    public Result show(){
        Result result = agritainmentService.show();
        return  result;
    }
    @PostMapping("imgInsert")
    public Result imgInsert(@RequestParam Integer id,@RequestBody MultipartFile file, @RequestParam(required = false) String name, @RequestParam(required = false) String content){
        Result result = agritainmentService.ImgInsert(id,file,name,content);
        return result;
    }
    @GetMapping("page")
    public Result page(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        Result result=agritainmentService.page(pageNum,pageSize);
        return result;
    }
}
